package com.mlc.wx.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.mlc.common.annotation.Log;
import com.mlc.common.enums.BusinessType;
import com.mlc.wx.domain.User;
import com.mlc.wx.service.IUserService;
import com.mlc.common.core.controller.BaseController;
import com.mlc.common.core.domain.AjaxResult;
import com.mlc.common.utils.poi.ExcelUtil;
import com.mlc.common.core.page.TableDataInfo;

/**
 * 微信用户Controller
 * 
 * @author ZFC
 * @date 2024-06-30
 */
@Controller
@RequestMapping("/wx/user")
public class UserController extends BaseController
{
    private String prefix = "wx/user";

    @Autowired
    private IUserService userService;

    @RequiresPermissions("wx:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询微信用户列表
     */
    @RequiresPermissions("wx:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(User user)
    {
        startPage();
        List<User> list = userService.selectUserList(user);
        return getDataTable(list);
    }

    @RequiresPermissions("wx:user:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap)
    {
        mmap.put("user", userService.selectUserById(id));
        return prefix + "/detail";
    }

    /**
     * 导出微信用户列表
     */
    @RequiresPermissions("wx:user:export")
    @Log(title = "微信用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(User user)
    {
        List<User> list = userService.selectUserList(user);
        ExcelUtil<User> util = new ExcelUtil<User>(User.class);
        return util.exportExcel(list, "微信用户数据");
    }

    /**
     * 删除微信用户
     */
    @RequiresPermissions("wx:user:remove")
    @Log(title = "微信用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(Long ids)
    {
        return toAjax(userService.updateUserById(ids));
    }
}
